home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ für Kids
/
C++ for kids.iso
/
Buch
/
Tafel1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-10
|
4KB
|
121 lines
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "Tafel1.h"
//---------------------------------------------------------------------------
#pragma link "Grids"
#pragma resource "*.dfm"
TStringList *Tabelle;
int Anzahl, Zeilen, Spalten;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GetTable (String DateiName)
{
// Tabelleninhalt laden
Tabelle->LoadFromFile (DateiName);
Anzahl = Tabelle->Count;
// Anzahl der Zeilen/Spalten ermitteln
Zeilen = StrToInt (Tabelle->Strings[Anzahl-2]);
Spalten = StrToInt (Tabelle->Strings[Anzahl-1]);
StringGrid1->RowCount = Zeilen;
StringGrid1->ColCount = Spalten;
// Zeilen-spaltenweise aus Tabelle in Stringgitter einlesen
for (int i=0; i<Zeilen; i++)
for (int j=0; j<Spalten; j++)
{
StringGrid1->Cells[j][i] = Tabelle->Strings[i*Spalten+j];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PutTable (String DateiName)
{
// Tabelle l÷schen
Tabelle->Clear ();
// Zeilen-spaltenweise aus Stringgitter in Tabelle kopieren
for (int i=0; i<StringGrid1->RowCount; i++)
for (int j=0; j<StringGrid1->ColCount; j++)
{
Tabelle->Add (StringGrid1->Cells[j][i]);
}
// Anzahl der Zeilen/Spalten merken
Tabelle->Add (IntToStr(StringGrid1->RowCount));
Tabelle->Add (IntToStr(StringGrid1->ColCount));
// Tabelleninhalt speichern
Tabelle->SaveToFile(DateiName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// Vorgabe der Zeilen/Spalten
StringGrid1->ColCount = 5;
StringGrid1->RowCount = 10;
StringGrid1->ColWidths[0] = 60;
StringGrid1->RowHeights[0] = 25;
StringGrid1->Align = alClient;
StringGrid1->Options << goEditing;
Tabelle = new TStringList ();
Spalten = StringGrid1->ColCount;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Neu1Click(TObject *Sender)
{
try
{
Anzahl = StrToInt(InputBox ("Anzahl der Zeilen:","",10));
Spalten = StrToInt(InputBox ("Anzahl der Spalten:","",5));
if (Anzahl <= 0) Anzahl = 1;
if (Spalten <= 0) Spalten = 1;
}
catch (...)
{
Anzahl = 10;
Spalten = 5;
}
StringGrid1->ColCount = Spalten;
StringGrid1->RowCount = Anzahl;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Oeffnen1Click(TObject *Sender)
{
if (OpenDialog1->Execute ())
GetTable (OpenDialog1->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Speichern1Click(TObject *Sender)
{
if (SaveDialog1->Execute ())
PutTable (SaveDialog1->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Ende1Click(TObject *Sender)
{
Close ();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Spaltenbreite1Click(TObject *Sender)
{
StringGrid1->ColWidths[StringGrid1->Col] =
StrToInt(InputBox ("Spaltenbreite:","",100));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Zeilenhoehe1Click(TObject *Sender)
{
StringGrid1->RowHeights[StringGrid1->Row] =
StrToInt(InputBox ("Zeilenh÷he:","",25));
}
//---------------------------------------------------------------------------